package com.comboo.example.web.api;

import org.springframework.data.domain.Page;

import java.util.List;

/**
 * @author Sherman
 * created in 2018/12/19
 */

public class ResponsePageWrapper<T> extends ResponseWrapper<T> {

    private Integer totalPage;

    private Integer pageSize;

    private Integer pageNo;

    private Long totalItems;

    public static <T> ResponsePageWrapper<List<T>> success(Page<T> page) {
        ResponsePageWrapper<List<T>> resp = new ResponsePageWrapper<>();
        resp.setPayload(page.getContent());
        resp.setPageNo(page.getNumber());
        resp.setPageSize(page.getSize());
        resp.setTotalItems(page.getTotalElements());
        resp.setCode(SUCCESS_CODE);
        resp.setMessage(SUCCESS_MESSAGE);
        return resp;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Long getTotalItems() {
        return totalItems;
    }

    public void setTotalItems(Long totalItems) {
        this.totalItems = totalItems;
    }

}
